package com.sgolub.commanndsonline.helpers;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConverterHelper {

	/* INPUT FORMAT  DD.MM.YYYY */
	
	
	public static Date convertToDate(String param){
		// Convert from String to date
		Date resultDate;
	    try {
	      resultDate = new SimpleDateFormat("dd.MM.yyyy").parse(param);
	      System.out.println("Parsed date = " + resultDate);
	      return resultDate;
	    } catch (ParseException e) {
	      e.printStackTrace();
	      return new Date();
	    }
	}
	
	public static Date convertToDateWS(String param){
		// Convert from String to date 2012-12-31T00:00:00
		System.out.println("PARAM convertToDateWS = " + param);
		String tmp = param.substring(0,10);
		System.out.println("TMP convertToDateWS =" + tmp + "=");
		Date resultDate;
	    try {
	      resultDate = new SimpleDateFormat("yyyy-MM-dd").parse(tmp);
	      System.out.println("Parsed date = " + resultDate);
	      return resultDate;
	    } catch (ParseException e) {
	      e.printStackTrace();
	      return new Date();
	    }	
	}
}
